package com.spring.campus_express_delivery.exception;

import com.spring.campus_express_delivery.util.ResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
//统一异常处理类
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * GlobalExceptionHandler
 * </p>
 *
 * @author biubiu
 * @since 2021/1/23
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)

    public Result<Object> exceptionHandler(Exception ex, HttpServletRequest request) {
        ResponseEntity responseEntity;
        LOGGER.error("url:{},|errMsg:{}", request.getRequestURI(), ex.getMessage(), ex);
        return Result.error(ex.getMessage());
    }

    @ExceptionHandler(SystemException.class)
    public Result<Object> paramExceptionHandler(SystemException ex, HttpServletRequest request) {
        LOGGER.error("url:{},|errMsg:{}", request.getRequestURI(), ex.getMessage());
        return Result.error(ex.getResultCode());
    }


}